//
//  CityViewController.m
//  VmiSJ
//
//  Created by 汪的一声就哭了！ on 2017/1/13.
//  Copyright © 2017年 汪的一声就哭了！. All rights reserved.
//

#import "CityViewController.h"

@interface CityViewController ()<UITableViewDelegate, UITableViewDataSource>
@property(nonatomic,strong) UITableView *tableView;

@end

@implementation CityViewController
{
    NSMutableArray *_listArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"所在城市";
    [self obtainListData];
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-64) style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.backgroundColor = BackColor;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.view addSubview:_tableView];
    [_tableView registerNib:[UINib nibWithNibName:@"WCSJTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell1"];
}

//设置单元格高度
- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}


//设置表视图中的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _listArray.count;
}

//设置单元格中的数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    WCSJTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
    cell.label.text = [_listArray[indexPath.row] categoryname];
    cell.backImageView.hidden = YES;
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if ([self.cityStr isEqualToString:[_listArray[indexPath.row] categoryname]]) {
        cell.backLabel.hidden = NO;
    } else {
        cell.backLabel.hidden = YES;
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ProvinceModel *model = _listArray[indexPath.row];
    [NetRequiest handleDataWithString:HTTPLOAD dictionary:@{@"v1":@"reviewmaterial",@"uid":UID,@"province":self.province_id,@"shi":model.the_id} HUD:YES block:^(id responseObject) {
        if ([responseObject[@"code"] isEqual:@200]) {
            [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
        }
        [[SQShowMessage shareMessage] showMessageWithStr:responseObject[@"msg"]];
    }];
}
#pragma mark -------------- 发布城市网络请求
- (void)obtainListData
{
    [NetRequiest handleDataWithString:[NSString stringWithFormat:@"%@?v1=country&province_id=%@",HTTPLOAD,self.province_id] dictionary:nil HUD:YES block:^(id responseObject) {
        if ([responseObject[@"code"] isEqual:@200]) {
            _listArray = [NSMutableArray array];
            for (NSDictionary *dic in responseObject[@"result"]) {
                ProvinceModel *model = [[ProvinceModel alloc] init];
                [model setValuesForKeysWithDictionary:dic];
                [_listArray addObject:model];
            }
            [self.tableView reloadData];
        } else {
            [[SQShowMessage shareMessage] showMessageWithStr:responseObject[@"msg"]];
        }
    }];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
